<template>
  <div class="kaocha">
    <el-dialog title="批示意见/办理提示" :visible.sync="noticeVisible" width="95%">
      <notice :noticePersonId="noticePersonId" :step="selStep"></notice>
      <div slot="footer" class="dialog-footer" style="overflow:hidden">
        <el-button @click.native="noticeVisible = false" style="float:right">关闭</el-button>
      </div>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item >考察</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxnoborder">
      <div :style="'height:'+tableHeight+'px'">
        <el-scrollbar style="height: calc(100% + 16px);">
          <el-radio-group v-model="departmentCode" @change="changedept" style="margin:15px 15px 0" class="pointRadio">
            <el-radio-button v-if="mangeDep.indexOf('干部一处')>-1" :label="1">
              <el-badge v-if="num1>0" :value="num1" class="item">干部一处事项</el-badge>
              <span v-else>干部一处事项</span>
            </el-radio-button>
            <el-radio-button v-if="mangeDep.indexOf('干部二处')>-1" :label="2">
              <el-badge v-if="num2>0" :value="num2" class="item">干部二处事项</el-badge>
              <span v-else>干部二处事项</span>
            </el-radio-button>
            <el-radio-button v-if="mangeDep.indexOf('干部三处')>-1" :label="3">
              <el-badge v-if="num3>0" :value="num3" class="item">干部三处事项</el-badge>
              <span v-else>干部三处事项</span>
            </el-radio-button>
          </el-radio-group>
          <div style="margin:15px;">
              <el-table
                :data="tableData3"
                v-loading="loading"
                border
                @selection-change="handleSelectionChange">
                <el-table-column
                  type="selection"
                  width="55">
                </el-table-column>
                <el-table-column
                  prop="realName"
                  label="姓名"
                  width="80">
                </el-table-column>
                <el-table-column
                  prop="candidateUnit"
                  label="目前单位"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="currentJob"
                  label="目前职务"
                  width="150"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="currentLevel"
                  label="目前职级"
                  width="100"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="unitName"
                  label="选任岗位单位"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="jobName"
                  label="选任岗位职务"
                  width="150"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  prop="jobLevel"
                  label="选任岗位职级"
                  width="110"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="批示意见/办理提示" width="150">
                  <template slot-scope="scope">
                    <el-popover placement="bottom" width="600" trigger="hover">
                      <notice :noticePersonId="scope.row.busCandidatePersonId" step="4"></notice>
                      <el-button slot="reference" type="primary" @click="showNotice(scope.row.busCandidatePersonId)">查看详情</el-button>
                    </el-popover>
                  </template>
                </el-table-column>
                <el-table-column
                  label="附件"
                  width="160">
                  <template slot-scope="scope">
                    <template v-if='scope.row.examinationFiles&&scope.row.examinationFiles.length>0'>
                      <div v-for="(item, index) of scope.row.examinationFiles" :key="index">
                        <a v-if="item.fileName&&item.fileName!==''" :href="$http.defaults.baseURL+$http.defaults.selectionAPI+'api/gen/file/download?id='+item.id">{{item.fileName}}.{{item.fileType}}</a>
                      </div>
                    </template>
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  width="100">
                  <template slot-scope="scope">
                    <el-button @click="detailShow(scope.row)" type="primary">查看</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <select-group :backflag="false" :selectData="selectData" :selectPerson="selectPerson" :selApi="selApi" :selStep="selStep" @getList="getList"></select-group>
            </div>
        </el-scrollbar>
      </div>
    </section>
  </div>
</template>

<script>
import notice from '../common/Notice'
import selectGroup from '../common/SelectGroup2'
export default {
  name: 'kaocha',
  components: {
    notice,
    selectGroup
  },
  data () {
    return {
      num1: 0,
      num2: 0,
      num3: 0,
      loading: false,
      mangeDep: '',
      departmentCode: '',
      tabdept: '1',
      tableHeight: 100,
      activeName: 'first',
      noticeVisible: false,
      noticePersonId: '',
      tableData: [],
      tableData2: [],
      tableData3: [],
      noticeTit: '办理提示',
      noticeData: [],
      noticeTit2: '批示意见',
      noticeData2: [],
      selectData: {
        hjData: [
        ],
        szData: [
        ],
        cnData: [],
        yyData: []
      },
      selectPerson: [],
      selApi: 'api/selection/approve/submitApprove',
      selStep: 4
    }
  },
  methods: {
    getNum () {
      let url = this.$http.defaults.selectionAPI + 'api/selection/statnum/examination/getStatNum2'
      // console.log(url)
      this.$http.get(url).then(res => {
        if (res.data.success === true) {
          this.num1 = res.data.result.num1
          this.num2 = res.data.result.num2
          this.num3 = res.data.result.num3
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    changedept () {
      this.selectData.hjData = []
      this.selectData.szData = []
      this.selectData.yyData = []
      this.loadSelectData()
      this.getList()
    },
    loadSelectData () {
      let departmentName = ''
      if (this.departmentCode === 1) {
        departmentName = '干部一处'
      } else if (this.departmentCode === 2) {
        departmentName = '干部二处'
      } else if (this.departmentCode === 3) {
        departmentName = '干部三处'
      }
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=1`)
        .then(response => {
          if (response.data.success) {
            this.selectData.hjData = []
            for (let i = 0; i < response.data.result.length; i++) {
              if (response.data.result[i].unitName === departmentName) {
                this.selectData.hjData.push(response.data.result[i])
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=2`)
        .then(response => {
          if (response.data.success) {
            this.selectData.szData = []
            for (let i = 0; i < response.data.result.length; i++) {
              if (response.data.result[i].roleName === 'ROLE_sizhang' || response.data.result[i].manageDep.indexOf(departmentName) > -1) {
                this.selectData.szData.push(response.data.result[i])
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/home/getCommonlyOpinions?step=4`)
        .then(response => {
          if (response.data.success) {
            this.selectData.yyData = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    handleSelectionChange (val) {
      console.log('handleSelectionChange:', val)
      this.selectPerson = [...val]
    },
    showNotice (id) {
      console.log('show notice id:', id)
      this.noticePersonId = id
      this.noticeVisible = true
    },
    getList () {
      this.getNum()
      this.loading = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/approve/getUserApproveList'
      // console.log(url)
      this.$http.post(url, {
        departmentCode: this.departmentCode,
        step: 4
      }).then(res => {
        console.log('get list33 succ:', res)
        if (res.data.success === true) {
          this.tableData3 = res.data.result
          this.loading = false
        } else {
          this.loading = false
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    goTuijianDetail (item) {
      console.log(item)
      this.$router.push({
        name: 'kaochad',
        params: item
      })
    },
    goTuijianDetail2 (item) {
      // console.log(item)
      this.$router.push({
        name: 'kaochad2',
        params: item
      })
    },
    detailShow (val) {
      console.log(val)
      this.$router.push({
        name: 'kaochads',
        params: val
      })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 165
      })
    }
  },
  mounted () {
    this.mangeDep = localStorage.getItem('mangeDep')
    if (!this.mangeDep || this.mangeDep === '') {
      this.mangeDep = []
    }
    let departmentCodes = []
    if (this.mangeDep.indexOf('干部一处') > -1) {
      departmentCodes.push(1)
    }
    if (this.mangeDep.indexOf('干部二处') > -1) {
      departmentCodes.push(2)
    }
    if (this.mangeDep.indexOf('干部三处') > -1) {
      departmentCodes.push(3)
    }
    this.departmentCode = departmentCodes[0]
    this.loadSelectData()
    this.getList()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
.kaocha .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
  border-bottom:1px solid #95B8E7;
}
.kaocha .el-table td, .el-table th.is-leaf{
  border-right:1px solid #95B8E7;
}
.kaocha .wboxnoborder .el-table{
  border: #95B8E7 solid 1px;
}
.kaocha .wboxnoborder .el-table th{
  font-weight: normal;
  background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  text-align: center;
  border-right: #95B8E7 solid 1px;
  border-bottom: #95B8E7 solid 1px;
  min-height: 30px;
  line-height:30px;
}
.kaocha .wboxnoborder .el-table td, .el-table th{
  padding:0;
  font-size:var(--size14) !important;
  line-height: 20px;
  font-family: '宋体';
  text-align: center;
}
.kaocha .el-table__row{
  height: 50px;
}
</style>
<style scoped>
.kaocha {
  width: 100%;
  box-sizing: border-box;
}
.kaocha .wboxnoborder {
  padding: 0;
  width: 100%;
  background-color: #fff;
  margin: 0 10px;
  overflow: hidden;
}
</style>
